import time

from tornado import web, ioloop


class MainHandler(web.RequestHandler):

    # 当客户端发起不同的http方法的时候，只需要重载handler中对应的方法即可
    async def get(self, *args, **kwargs):
        self.write("hello world 3!")


class SleepHandler(web.RequestHandler):

    async def get(self, *args, **kwargs):
        # 在编写中不能在里面写同步IO逻辑
        time.sleep(10)
        self.write("sleep")


if __name__ == '__main__':
    app = web.Application([
        ("/", MainHandler),
        ("/sleep", SleepHandler)
    ], debug=True)

    app.listen(8000)

    ioloop.IOLoop.current().start()
